﻿using System;
using System.Collections.Generic;
using GearOptimizer.Adapters;
using GearOptimizer.ExtensionMethods;

namespace GearOptimizer.Factories
{
    public class MemoryRepositoryFactory : IRepositoryFactory
    {
        private readonly IDictionary<Type, Object> repositoryDictionary = new Dictionary<Type, object>();
        public IRepository<T> GetRepository<T>() where T : IIdentifiable
        {
            var repository = repositoryDictionary.Get(typeof (T)) as IRepository<T>;
            if (repository == null)
            {
                repositoryDictionary[typeof (T)] = repository = new MemoryRepository<T>();
            }
            return repository;
        }
    }
}